package cn.tedu.controller;

import cn.tedu.dao.ActDao;
import cn.tedu.dao.BannerDao;
import cn.tedu.entity.Act;
import cn.tedu.entity.Banner;
import cn.tedu.entity.User;
import cn.tedu.utils.ThUtils;
import org.thymeleaf.context.Context;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "ActiveServlet",urlPatterns = "/act")
public class ActiveServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Context context = new Context();
        ActDao aDao = new ActDao();
        List<Act> aList = aDao.findAll();
        context.setVariable("aList",aList);
        //获取Session对象
        HttpSession session = request.getSession();
        //取出保存的用户对象
        User user = (User) session.getAttribute("user");
        System.out.println(user);
        if(user!=null){
            if (user.getId()==1){
                context.setVariable("admin",user);
                ThUtils.print("activity.html",context,response);
                return;
            }
        }
        context.setVariable("admin", null);
        ThUtils.print("activity.html",context,response);
    }
}
